package com.example.java.base.concurrency.threadpool;

import com.example.java.base.concurrency.threadpool.task.ExecutorTask;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * A7_ScheduledThreadPoolTest:创建一个线程池，该线程池可以安排命令在给定的延迟后运行或定期执行
 *
 * @author zhangxiaoxiang
 * @date 2020/11/5
 */
@Slf4j
public class A7ScheduledThreadPoolTest {

    public static void main(String[] args) {
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(10);
//        threadPool.schedule(new Task(), 5, TimeUnit.SECONDS);
        log.info("开始计时,初始化线程3秒,间隔5秒创建一个线程");
        threadPool.scheduleAtFixedRate(new ExecutorTask(), 3, 5, TimeUnit.SECONDS);
    }
}
